-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add the "valid-license" rule #786
base: main
Are you sure you want to change the base?
feat: add the "valid-license" rule #786
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this! This was a good prod to close out the conversation in #51 about how we want to approach all these requirements. I posted #51 (comment).
Left a couple of initial review comments here in case you feel motivated to work on this before we're certain this is the direction for the package. Cheers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the rule and rule test files aren't named consistently with the rule itself requires-license
vs require-license
d97ae03
to
3b6a152
Compare
Rookie error, fixed. |
3b6a152
to
7019c1b
Compare
Thanks for your patience as we worked out the long-term strategy for the rules in this plugin. What we landed on in #51 is that we want to have separate rules for requiring a property and for validating the correctness of that property (if it exists). That way people can use one or the other, or both. So for |
Actually, on second though, why don't we convert this one into the |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #786 +/- ##
==========================================
+ Coverage 98.71% 98.78% +0.07%
==========================================
Files 19 20 +1
Lines 1163 1234 +71
Branches 139 146 +7
==========================================
+ Hits 1148 1219 +71
Misses 15 15 ☔ View full report in Codecov by Sentry. |
No problem, can rework this rule to check for validity.
|
Actually that went back and forth a couple of times (my bad 😅). Where we landed is that |
I already put up a PR that lays the groundwork for our approach to |
Just working on this now, looks like the changes would be essentially cosmetic to match what was discussed. The rule currently has a check that if the property is present that it also must be a string. I don't think there is anything in the current discussion about where type checking of the value should live in |
The require- rules won't do any checking of the value. It'll just simply check whether the property is presentor not. |
- Added extra valid test case for missing property - Fix documentation - Fix linting errors
bfa389f
to
84289f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Progress 🚀
invalidValue: '"license" must be{{multiple}} {{allowed}}"', | ||
nonString: '"license" must be a string"', | ||
}, | ||
schema: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Feature] If this rule is to be enabled in the recommended config -which would be great!- then we're going to need it to not be prescriptive on which of the "valid" license(s) are allowed. Any "valid" license should be allowed unless the user has customized the rule. "Valid" here could mean one of several things, depending on how strict the user wants to be. In increasing order of strictness...
- 🍏 Any string value
- 🍌 Any SPDX license ID (on npm:
spdx-license-ids
) or SPDX license expression syntax referring to SPDX license IDs - 🌸 The same as 2., but only OSI approved license IDs
- 🐉 The same as 2., but only FSF Free/Libre approved license IDs
- 🥚 >=1 specific license IDs (what the PR has right now)
I think any of 2 🍌, 3 🌸, 4 🐉, and 5 🥚 would be fine as followup issues (with the caveat that 3 🌸 and 4 🐉 depend on 2 🍌). Most users would be satisfied with just 1 🍏 checking that it's a string.
But, the options right now don't allow 1 🍏. They require 5 🥚, passing in a specific list of IDs. Could you please make the 5 🥚 specific license ID checking optional? As in, if the user doesn't provide any licenses, the rule should only check 1 🍏 that it's a valid string.
Reference: https://docs.npmjs.com/cli/v11/configuring-npm/package-json#license
|
||
ruleTester.run("valid-license", rule, { | ||
invalid: [ | ||
// Invalid with single valid value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Docs] Nit: IMO these comments aren't worth keeping up-to-date. ESLint rule tests tend to get very nuanced and tricky over time. I've seen suits with many dozens or even hundreds of tests that exercise various edge cases on themes. Personally I'd remove this:
// Invalid with single valid value |
If you really want to include a name per test, the proper way would be with a name
property per https://eslint.org/docs/latest/integrate/nodejs-api#ruletester.
Not a blocker, just a preference. 🙂
PR Checklist
status: accepting prs
Overview
Adds a new rule that enforces the 'licence' value in the package.json to be a specific value, or one of a selection of values.
Proposing this as a new rule to eliminate my usage of npm-package-json-lint, since this was the only feature I needed from it.
I did have this as a custom rule in my own ESLint plugin, but I found out it's very difficult to apply multiple plugins to the same file and I am already using this plugin.
This rule could expand in scope to allow for any value to be validated in the same way.